/**
* @depends jquery.ui.js
*/

(function($) {

	$.widget( 'ui.dotify', {
		
		_init: function() {
			
			var width = this.element.width();
			this.element.css( {
				'white-space': 'nowrap',
				'position': 'absolute',
				'width': 'auto'
			} );
			var text = this.element.text();
			var flag = text;
			text = text.replace( /\n.*$/g, '' );
			text = text.substr( 0, Math.floor(width / this.options.minCharWidth) );
			this.element.text( text );
			while( this.element.width() > width ) {
				text = text.substr( 0, text.length - 1 );
				this.element.text( text );
			}
			if( text != flag ) {
				text = text.substr( 0, text.length - 2 );
				this.element.text( text + '...' );
			}
			this.element.css( 'width' , width );
			this.element.css( 'white-space', 'wrap' );
		},
		
		options: {
			minCharWidth: 4
		}
		
	} );
	
})(jQuery);
